import {
  Controller,
  Get,
  Post,
  Body,
  UsePipes,
  ValidationPipe,
} from '@nestjs/common';
import { SettingsService } from '../services/settings.service';
import { UserProfile } from '../models/user-profile.entity';
import { SystemSetting } from '../models/system-setting.entity';
import { ChartData } from '../models/chart-data.entity';

@Controller('settings')
export class SettingsController {
  constructor(private readonly settingsService: SettingsService) {}

  @Get('user-profile')
  async getUserProfile(): Promise<UserProfile | null> {
    return this.settingsService.getUserProfile();
  }

  @Post('user-profile')
  @UsePipes(new ValidationPipe())
  async updateUserProfile(
    @Body() profileData: Partial<UserProfile>,
  ): Promise<UserProfile> {
    return this.settingsService.updateUserProfile(profileData);
  }

  @Get('system')
  async getSystemSettings(): Promise<SystemSetting | null> {
    return this.settingsService.getSystemSettings();
  }

  @Post('system')
  @UsePipes(new ValidationPipe())
  async updateSystemSettings(
    @Body() settingsData: Partial<SystemSetting>,
  ): Promise<SystemSetting> {
    return this.settingsService.updateSystemSettings(settingsData);
  }

  @Get('chart-data')
  async getChartData(): Promise<ChartData[]> {
    return this.settingsService.getChartData();
  }
}
